//
//  IMLoginManager.swift
//  MT
//
//  Created by ooops on 2019/12/16.
//  Copyright © 2019 张强. All rights reserved.
//

import UIKit
import JMessage
import DeviceKit

class IMLoginManager: NSObject {

    typealias complete = () -> ()
    

    static let sharedInstance: IMLoginManager = {
        let instance = IMLoginManager()
        return instance
    }()
    
    class func login(_ userName: String, _ password: String, complete: @escaping complete, falid: @escaping complete) {
        if Device.current.isSimulator {
            IMLoginManager.sharedInstance.jmessageLogin(userName: userName, password: password, complete: complete, falid: falid)
        } else {
            IMLoginManager.sharedInstance.jmessageLogin(userName: userName, password: password, complete: complete, falid: falid)
        }
    }
    
    func jmessageLogin(userName: String, password: String, complete: @escaping complete, falid: @escaping complete) {
        JMSGUser.login(withUsername: userName, password: password) { (result, error) in
            if error != nil {
                falid()
            } else {
                complete()
            }
        }
    }
    
    class func logout() {
        JMSGUser.logout { (result, error) in
            /// 移除本地信息
        }
    }
}
